package com.qingcheng.controller;

import com.qingcheng.entity.Result;
import com.qingcheng.pojo.order.Statistics;
import com.qingcheng.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;

// 统计管理
@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    // 定时插入
  @PostMapping("/deal")
    public Result deal(@RequestBody  Map<String,String> map){
        Statistics statistics = statisticsService.deal(map.get("date1"),map.get("date2"));
        return new Result(200,"查询成功",statistics);
    }

//      交易统计的数据查询
     @PostMapping("/dealfind")
     public Result dealfind(@RequestBody  Map<String,String> map){
        map.put("date1",map.get("date1").substring(0,10));
        if(map.get("date2")==null){
            LocalDate date=LocalDate.now();
            map.put("date2",date.toString());
        }
         Statistics statistics = statisticsService.dealfind(map);
         List<Statistics> list=new ArrayList<Statistics>();
         list.add(statistics);
        return new Result(200,"查询成功",list);
     }

     // 查询商品统计数据
     @PostMapping("/goodsfind")
     public Result goodsfind(@RequestBody Map map){
           map.put("date1",LocalDate.of(2019,04,15).toString());
           map.put("date2",LocalDate.of(2019,04,16).toString());
           List<HashMap> hashMap= statisticsService.goodsfind(map);
           return new Result(200,"查询成功",hashMap);
     }

     // 订单来源
    @PostMapping("/orderSource")
    public Result orderSource(LocalDate date1,LocalDate date2){
        List<HashMap> hashMaps = statisticsService.orderSource(date1, date2);
        return new Result(200,"查询成功",hashMaps);
    }

}
